from time import sleep

from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from APPauto.test_APPauto_practice.test_enterprise_wechat_app.po_add_del_member.package.add_member_package import \
    AddMemberPackage
from APPauto.test_APPauto_practice.test_enterprise_wechat_app.po_add_del_member.package.base import Base
from APPauto.test_APPauto_practice.test_enterprise_wechat_app.po_add_del_member.package.personal_info_package import \
    PersonalInfoPackage


class AddressBookPackage(Base):

    def get_add_member_package(self):
        """进入添加用户页面"""
        self.driver.find_element(MobileBy.XPATH,"//*[@text='添加成员']").click()
        return AddMemberPackage(self.driver)

    def get_personal_info_package(self):
        """搜索后进入个人信息页面"""
        self.driver.find_element(MobileBy.ID, "com.tencent.wework:id/igk").click()
        self.driver.find_element(MobileBy.XPATH, "//*[@text='搜索']").send_keys("成员01")
        # ele = (MobileBy.XPATH, "//*[@text='成员01']")[1]
        # WebDriverWait(self.driver,10).until(expected_conditions.element_to_be_clickable(ele))
        sleep(10)
        members = self.driver.find_elements(MobileBy.XPATH, "//*[@text='成员01']")
        members[1].click()
        # 此处为 find_elements 不是 find_element,特别注意，find_element只能查找一个元素，find_elements查找满足条件的所有元素
        return [PersonalInfoPackage(self.driver),len(members)]
